added samples
[windows-sources.git] / sdk / samples / all in on code / Visual Studio 2008 / VBWin7TriggerStartService / ServiceInstaller.vb
blobf3ca5ae8b0f73cf647f57021bf4642b769d3e8f8
1 '************************************** Module Header **************************************'
2 ' Module Name: ServiceInstaller.vb
3 ' Project: VBWin7TriggerStartService
4 ' Copyright (c) Microsoft Corporation.
5 '
6 ' In ServiceInstaller, we configure the service to start when a generic USB disk becomes
7 ' available. It also shows how to trigger-start when the first IP address becomes available,
8 ' and trigger-stop when the last IP address becomes unavailable.
9 '
10 ' This source is subject to the Microsoft Public License.
11 ' See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
12 ' All other rights reserved.
14 ' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
15 ' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
16 ' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
17 '*******************************************************************************************'
19 #Region "Imports directives"
21 Imports System.ComponentModel
22 Imports System.Configuration.Install
23 Imports System.ServiceProcess
24 Imports System.Runtime.InteropServices
26 #End Region
29 Public Class ServiceInstaller
31 Public Sub New()
32 MyBase.New()
33 'This call is required by the Component Designer.
34 InitializeComponent()
35 End Sub
38 Private Sub ServiceInstaller1_AfterInstall(ByVal sender As System.Object, ByVal e As System.Configuration.Install.InstallEventArgs) Handles ServiceInstaller1.AfterInstall
40 ' If Service Trigger Start is supported on the current system, configure the service
41 ' to trigger start.
42 If (ServiceTriggerStart.IsSupported) Then
43 Console.WriteLine("Configuring trigger-start service...")
44 Try
45 ' Set the service to trigger-start when a generic USB disk becomes available.
46 ServiceTriggerStart.SetServiceTriggerStartOnUSBArrival( _
47 ServiceInstaller1.ServiceName)
49 ' [-or-]
51 ' Set the service to trigger-start when the first IP address becomes
52 ' available, and trigger-stop when the last IP address becomes unavailable.
53 'ServiceTriggerStart.SetServiceTriggerStartOnIPAddressArrival( _
54 'ServiceInstaller1.ServiceName)
56 Catch ex As Exception
57 Console.WriteLine("Service Trigger Start configuration failed with " & ex.Message)
58 End Try
59 Else
60 Console.WriteLine("The current system does not support trigger-start service.")
61 End If
63 End Sub
65 End Class